<?php  
	namespace Admin\Controller;
	class NumberController extends CommonController
	{
		public function index()
		{
			$list = M('project') -> select();
			$this -> assign('list',$list);
			$this -> display();
		}

		public function add()
		{
			if(IS_POST){
				$opt = trim(I('post.opt'));
				$point = trim(I('post.point'));
				$pname = trim(I('post.pname'));

				if (!empty($opt) && !empty($point) && !empty($pname)) 
				{
					$num = M('project')->where("pname='{$pname}'")->count();
					if ($num === '0') 
					{
						$data = [
								'opt' => $opt,
								'point' => $point,
								'pname' => $pname
								];
						M('project')->data($data)->add();
					}
				}
				$this -> redirect('Number/index');
			}
			$this->display();
			
		}

		public function edit()
		{
			if(IS_POST){
				$id = trim(I('post.id'));
				$opt = trim(I('post.opt'));
				$point = trim(I('post.point'));
				$pname = trim(I('post.pname'));
				if (!empty($opt) && !empty($point) && !empty($pname))
				{
					$where['pid'] = $id;
					$data = [
							'opt' => $opt,
							'point' => $point,
							'pname' => $pname
							];
					M('project') -> where($where) -> save($data);
				}
				$this -> redirect('Number/index');
			}
			$id = trim(I('id'));
			$item = M('project')->find($id);
			$this->assign('item',$item);
			$this->display();
			
		}

		public function del()
		{
			$id = trim(I('id'));
			M('project')->where("pid={$id}")->delete();
			$this->ajaxReturn(array('code'=>1,'msg'=>ok));
		}
	}